package com.vavr.checkincms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vavr.checkincms.domain.data.CheckinRecordsDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectKey;

/**
 * CheckinRecordsMapper
 *
 * @see CheckinRecordsDO
 * @since 2024.08
 */
@Mapper
public interface CheckinRecordsMapper extends BaseMapper<CheckinRecordsDO> {

    /**
     * 插入签到记录
     *
     * @param recordsDO {@link CheckinRecordsDO}
     * @return 写入条数
     */
    @Insert("INSERT INTO checkin_records (check_id, tel,name, organization, meeting_id,user_id) "
            + "VALUES (#{checkId}, #{tel}, #{name}, #{organization}, #{meetingId}, #{userId})")
    @SelectKey(statement = "SELECT FLOOR((1 + (RAND() * 10000000)))", keyProperty = "checkId", before = true, resultType = Long.class)
    @Options(useGeneratedKeys = true, keyProperty = "checkId", keyColumn = "check_id")
    int insertCheckinRecord(CheckinRecordsDO recordsDO);
}
